﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GrouponDesktop.ComprarGiftCard
{
    public partial class Buscar : Form
    {
        private TextBox tb;
        private TextBox id;
        private int overload = 0;

        public Buscar(TextBox nom, TextBox idDes)
        {
            this.tb = nom;
            this.id = idDes;
            InitializeComponent();
        }

        public Buscar(TextBox tb, int ol)
        {
            this.overload = ol;
            this.id = tb;
            InitializeComponent();

        }

        private void b_busc_Click(object sender, EventArgs e)
        {
            if (this.overload == 0)
            {
                BDConnection.FillGrid(" EXEC CodingSpree.buscUser '" + tb_busc.Text + "'", dgv_Busc);
                dgv_Busc.Columns[0].Width = 210;
                dgv_Busc.Columns[1].Width = 210;
                dgv_Busc.Columns[2].Visible = false;
            }
            else
            {
                BDConnection.FillGrid("select id_proveedores, razon_social, (select rubro from CodingSpree.TL_RUBROS RUB where RUB.id_rubro = PROV.id_rubro), telefono from CodingSpree.TL_PROVEEDORES PROV", dgv_Busc);
            }
        }

        private void b_select_Click(object sender, EventArgs e)
        {
            if (dgv_Busc.Rows.Count > 0)
            {
                if (this.overload == 0)
                {
                    tb.Text = (string)dgv_Busc.SelectedCells[0].Value + " " + (string)dgv_Busc.SelectedCells[1].Value;
                    id.Text = dgv_Busc.SelectedRows[0].Cells["id_cliente"].Value.ToString();
                    this.Hide();
                }
                else
                {
                    this.id.Text = dgv_Busc.SelectedRows[0].Cells["id_proveedores"].Value.ToString();
                    this.Hide();
                }
            }
            else
            {
                MessageBox.Show("No se seleccionó ningun campo");
            }
        }




    }
}
